package goodsManagment;

public class GoodsManagment {

	Goods[] gos = new Goods[10];


	Goods[] goods = new Goods[10];
	int count;
Goods go = new Goods();

//1.进货
	public boolean add(Goods go) {
		for (int i = 0; i < gos.length && gos[i] != null; i++) {
			if (gos[i].getName() == go.getName()) {
				return false;
			} 
		}
		if(count < gos.length) {
			gos[count++] = go;
			return true;
		}else {
			return false;
		}
	}
//2.卖货
	public boolean sellgoods(Goods go) {
		for (int i = 0; i < gos.length && gos[i] != null; i++) {
			if (gos[i].getName() == go.getName()) {
				gos[--count] = null;
				return true;
			} 
		}
		return false;
	}
//3.根据数量查库存
	Goods[] good = new Goods[200];
	

	public Goods[] goodsNum(int num) {
		Goods[] copy = new Goods[count];
		int index = 0;
		for (int i = 0; i < good.length && good[i] != null; i++) {
			if (good[i].getNum() == num) {
				copy[index++] = good[i];
			}
		}
		return copy.length == 0 ? null : copy;
	}

	// 4.输入货物改价格
	// 张爽
	public boolean update(Goods go) {
		// 根据id 找员工，更新其他信息
		for (int i = 0; i < good.length && good[i] != null; i++) {
			if (good[i].getPrice() == go.getPrice()) {
				good[i] = go;
				return true;
			}
		}
		return false;
	}
//5.根据销量排序
//TODO 仲福维
//6.根据价格排序
//TODO 仲福维
//7.删除商品
//TODO 任浩
public boolean remove(String name) {
	for (int i = 0; i < goods.length && goods[i] != null ; i++) {
		if (goods[i].getName().equals(name)) {
			for (int j = i + 1; j < count; j++) {
				goods[j-1] = goods[j];
			}
			goods[--count] = null;
			return true;
		}
	}
	return false;
}
//8.根据名称查货物
//TODO 任浩
public boolean update(GoodsManagment good) {
	for (int i = 0; i < goods.length && goods[i] != null; i++) {
		if (goods[i].getName().equals(good)) {
			return true;
		}
	}
	return false;
}
}
